package com.wanbangee.marksystem.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wanbangee.marksystem.entities.MExam;
import com.wanbangee.marksystem.entities.MExamMarker;
import com.wanbangee.marksystem.entities.MSubject;
import com.wanbangee.marksystem.service.ProgressCheckService;
/**
 * 进度监控
 * @author 王志雄
 *
 */
@RestController
@RequestMapping("progress")
public class ProgressCheckController {
	
	@Autowired
	private ProgressCheckService progressCheckService;

	/**
	 * 用于进度监控的列表显示界面
	 * @param schId
	 * @param teaId
	 * @return
	 */
	@GetMapping("setting/selectProgressList/{examId}/{examSubId}")
	public Map selectProgressList(@PathVariable("examId")Integer examId,@PathVariable("examSubId")Integer examSubId) {
		return progressCheckService.selectProgressList(examId, examSubId);
	}
	
	/**
	 * 分解阅卷任务
	 */
	@GetMapping("setting/updateExamResolve/{examId}/{examSubId}/teaId")
	public Map updateExamResolve() {
		
		return null;
	}
	/**
	 * 根据当前登录人所在学校ID查询当前时间已经开始但未过期的考试信息
	 */
	@GetMapping("setting/selectExamId/{schId}/{date}")
	public Map selectExamId(@PathVariable("schId")Integer schId,@PathVariable("date")String date) {
		List<MExam> mExams = progressCheckService.selectExamId(schId, date);
		HashMap<String,Object> map = new HashMap<>();
		if (mExams == null|| mExams.size()==0) {
			map.put("code", 10013);
			map.put("result", mExams);
		}else {
			map.put("code", 1001);
			map.put("result", mExams);
		}
		return map;  
	} 
	/**
	 * 查询考试科目 Id 通过考试 Id
	 * @param examId
	 * @return
	 */
	
	@GetMapping("setting/selectMSubjectByExamId/{examId}")
	public Map selectMSubjectByExamId(@PathVariable("examId")Integer examId) {
		List<MSubject> mSubjects = progressCheckService.selectMSubjectByExamId(examId);
		HashMap<String,Object> map = new HashMap<>();
		if (mSubjects == null|| mSubjects.size()==0) {
			map.put("code", 10013);
			map.put("result", null);
		}else {
			map.put("code", 1001);
			map.put("result", mSubjects);
		}
		return map;
	}
	/**
	 * 添加阅卷人
	 * @param mExamMarker
	 * @return
	 */
	@PostMapping("setting/insertMExamMarker")
	public Map insertMExamMarker(@RequestBody MExamMarker mExamMarker) {
		Integer result = progressCheckService.insertMExamMarker(mExamMarker);
		HashMap<String,Object> map = new HashMap<>();
		if (result ==0) {
			map.put("code", 10013);
			map.put("result", null);
		}else {
			map.put("code", 1001);
			map.put("result", result);
		}
		return map;
	}
	
	/**
	 * 分解阅卷任务的候选人列表
	 * @return
	 */
	@GetMapping("setting/selectExamTeaCandidate/{examId}/{examSubId}/{topicNo}")
	public Map selectExamTeaCandidate(@PathVariable("examId")Integer examId,@PathVariable("examSubId")Integer examSubId,@PathVariable("topicNo")Integer topicNo) {
		List<MExamMarker> mExamMarkers = progressCheckService.selectExamTeaCandidate(examId, examSubId, topicNo);
		HashMap<String,Object> map = new HashMap<>();
		if (mExamMarkers == null|| mExamMarkers.size()==0) {
			map.put("code", 10013);
			map.put("result", null);
		}else {
			map.put("code", 1001);
			map.put("result", mExamMarkers);
		}
		return map;
	}
	/**
	 * 更新阅卷的数量
	 * @param oldMarkerId
	 * @param topicCount
	 * @param newMarkerId
	 * @return
	 */
	@PostMapping("setting/updateMExamMarkerCount")
	public Integer updateMExamMarkerCount(@RequestParam("oldMarkerId")Integer oldMarkerId,@RequestParam("topicCount")Integer topicCount,@RequestParam("newMarkerId")Integer newMarkerId ) {
		return progressCheckService.updateMExamMarkerCount(oldMarkerId, topicCount, newMarkerId);
	}
	/**
	 * 查询要添加的阅卷人的 tea_id等信息----用于分解阅卷任务
	 * @param markerId
	 * @return
	 */
	@GetMapping("setting/selectMExamMarkerByMarkerIdOnResolver/{markerId}")
	public MExamMarker selectMExamMarkerByMarkerIdOnResolver(@PathVariable("markerId")Integer markerId) {
		return progressCheckService.selectMExamMarkerByMarkerIdOnResolver(markerId);
	}
	
	/**
	 * 查询重评列表
	 * @param teaId
	 * @param schId
	 * @return
	 */
	@GetMapping("setting/selectMExamMarkersRepeatList/{teaId}/{schId}")
	public List<MExamMarker> selectMExamMarkersRepeatList(@PathVariable("teaId")Integer teaId,@PathVariable("schId")Integer schId){
		return progressCheckService.selectMExamMarkersRepeatList(teaId, schId);
	} 
	
}
